package com.douwong.student.popuwindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.view.AnimImageView;

import java.util.ArrayList;
import java.util.List;


public class UpLoadPopuWindow extends PopupWindow {

	private Context context;
	private View view;
	private ImageView load_img;
	private TextView progress_text;

	private List<Integer> mIntegers;
	private final AnimImageView mAnimImageView;

	public UpLoadPopuWindow(Context context) {
		this.context = context;
		LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view=inflater.inflate(R.layout.upload_layout, null);
		load_img=(ImageView) view.findViewById(R.id.load_img);
		progress_text=(TextView) view.findViewById(R.id.progress_text);
		mIntegers	=new ArrayList<>();
		initResoursId();
		mAnimImageView = new AnimImageView();
		mAnimImageView.setAnimation(load_img,mIntegers);
		mAnimImageView.start(true,100);
	//	load_img.setBackgroundResource(R.drawable.load_anim);
	//	animationDrawable = (AnimationDrawable) load_img.getBackground();
	//	animationDrawable.start();
		this.setContentView(view);
		this.setWidth(LayoutParams.MATCH_PARENT);
		this.setHeight(LayoutParams.MATCH_PARENT);
		// 设置SelectPicPopupWindow弹出窗体可点击

		this.setFocusable(true);
		ColorDrawable dw = new ColorDrawable(0x00000000);
		this.setBackgroundDrawable(dw);
	}

    /**
     * 开启动画
     */
    public void  startAnimal(){
        mAnimImageView.start(true,100);
    }

	/**
	 * 初始化资源Id
	 */



	private void initResoursId() {
		mIntegers.add(R.mipmap.load_1);
		mIntegers.add(R.mipmap.load_2);
		mIntegers.add(R.mipmap.load_3);
		mIntegers.add(R.mipmap.load_4);
		mIntegers.add(R.mipmap.load_5);
		mIntegers.add(R.mipmap.load_6);
		mIntegers.add(R.mipmap.load_7);
		mIntegers.add(R.mipmap.load_8);
		mIntegers.add(R.mipmap.load_9);
		mIntegers.add(R.mipmap.load_10);
		mIntegers.add(R.mipmap.load_11);
		mIntegers.add(R.mipmap.load_12);


	}

	//设置上传进度
	public void setProgress(int progress){
		progress_text.setText(progress+"%");
	}
	public void setText(String str){
		progress_text.setText(str);
	}
	public String getText(){
		return progress_text.getText().toString();
	}
	@Override
	public void dismiss() {
		super.dismiss();
/*		if (animationDrawable != null) {
			animationDrawable.stop();
			for (int i = 0; i < animationDrawable.getNumberOfFrames(); i++) {
				Drawable frame = animationDrawable.getFrame(i);
				if (frame instanceof BitmapDrawable) {
					((BitmapDrawable) frame).getBitmap().recycle();
				}
				frame.setCallback(null);
			}
			animationDrawable.setCallback(null);
		}*/


if (mAnimImageView!=null){
	mAnimImageView.stop();

}
	}
	}
	
	

